function member_model()
{
	//#################################################################
	//
	// 조회부
	//
	//#################################################################
	// 목록 조회
	var _listPage 	= new PageInfo( document.getElementById( 'selectModels' ) );
	$( "#modelRefresh" ).click(function(e) {
		selectAllModels( _listPage.current, _listPage.numPerPage, modelRefreshSuccess, modelRefreshFail );
	});
	
	// 조회 성공
	function modelRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[모델 조회] 성공' );
		
		setModelListTable( data, $( "#selectModels>.list" ), _listPage );
	}
	
	// 조회 실패
	function modelRefreshFail( data )
	{
		setResultFailForJSON( '[모델 조회] 실패', data );
	};
	
	// 상세 팝업 활성 > // {s_code: "1", avg: "1", count: "1"}
	var _modelStatAVGs;
	function getStatAVG( statCode, avgFunction )
	{
		for( var idx in _modelStatAVGs )
		{
			if( _modelStatAVGs[ idx ].s_code == statCode )
			{
				if( avgFunction == null )
				{
					return _modelStatAVGs[ idx ].avg;
				}else{
					return avgFunction.call( null, Number(_modelStatAVGs[ idx ].avg), Number(_modelStatAVGs[ idx ].count) );
				}
			}
		}
	}
	function showDetailModelPopup( $model_code )
	{
		$.post( getGatePath(),
			{
				__key__: 'selectModel',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $model_code,
				includeDetail: 'Y'
			}, 
			function( data )
			{
				if( data.result == "SUCCESS" )
				{
					setResult( '[모델 상세 정보 조회] 성공' );
					
					// [[ 팝업 셋팅 ]]
					$popup = $( "#updateModel" );
					$popup.show();
					
					// 팝업이 설정과 동시에 공통변수 설정
					$popup.find( '.modelCode' ).val( data[ 'code' ] );
					
					$popup.find( '[name="code"]' ).val(		data[ 'code' ] );
					$popup.find( '[name="name"]' ).val( 	data[ 'name' ] );
					
					// 사진
					$popup.find( '.picture' ).empty().append( data[ 'picture' ] + createViewImageLink( data[ 'picture' ] ) );
					
					// 썸네일 정보
					var _thumbnails = [];
					if( data[ 'thumbnails' ] && data[ 'thumbnails' ][ 'thumb' ] )
					{
						for( var idx in data[ 'thumbnails' ][ 'thumb' ] )
						{
							var _link = data[ 'thumbnails' ][ 'thumb' ][ idx ].link;
							_thumbnails.push( 'no.'+(idx+1)+' '+_link+'('+createViewImageLink(_link)+')' );
						}
					}
					$popup.find( '.thumbs' ).empty().append( _thumbnails.join( '<br/>' ) );	
					
					// 기타 설정
					$popup.find( '[name="birthDate"]' ).val( 		data[ 'birth_date' ] );
					$popup.find( '[name="birthRegion"]' ).val( 		data[ 'birth_region' ] );
					$popup.find( '[name="education"]' ).val( 		data[ 'last_edu' ] );
					$popup.find( '[name="education_memo"]' ).val( 	data[ 'last_edu_memo' ] );
					$popup.find( '[name="sex"]' ).val( 				data[ 'sex' ] );
					$popup.find( '[name="military"]' ).val( 		data[ 'military' ] );
					$popup.find( '[name="military_memo"]' ).val( 	data[ 'military_memo' ] );
					$popup.find( '[name="height"]' ).val( 			data[ 'height' ] );
					$popup.find( '[name="ref"]' ).val( 				data[ 'ref' ] );
					$popup.find( '[name="ref_license"]' ).val( 		data[ 'ref_license' ] );
					
					// 평점 기록
					_modelStatAVGs = data[ 'avg' ];
					
					// 정당 히스토리
					selectModelParty( $model_code );
					// 직책 히스토리
					selectModelDuty( $model_code );
					// 약력 히스토리
					selectModelHistory( $model_code );
					// 당선 히스토리
					selectModelElection( $model_code );
					// 연관 사업
					selectModelBussiness( $model_code );
					// SNS
					selectModelSns( $model_code );
					// TAG
					selectModelTags( $model_code );
					
					// 입력 능력치 
					setStatField( $model_code );
					// 즐겨찾기
					selectMemberModelFavorite( $model_code );
					// 댓글 가져오기
					$( '#btn_modelCommentRefresh' ).click();
				}else{
					setResultFailForJSON( '[모델 상세 정보 조회] 실패', data );
				}
			},
			'json' );
	}
	
	// 클라이언트 리스트
	$( '#modelSelectByMenu' ).change(function(e) {
        e.preventDefault();
		
		var _values = ( $( this ).val() ).split( '|' );
		
		var _type = _values[0];
		var _code = _values[1];
		
		// 
		$.post( getGatePath(),
		{
			__key__: 'selectModels',
			__returnType__: 'json',
			page: 1,
			numPerPage: 20,
			type: _type,
			code: _code
		},
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				// 완료 콜백
				modelRefreshSuccess( data );
			}else{
				// 실패 콜백
				modelRefreshFail( data );
			}
		},
		'json' );
    });
	
	//#################################################################
	//
	// 정당 정보
	//
	//#################################################################
	// 조회
	function selectModelParty( $model_code )
	{
		var $container = $( '#modelParty>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelParty',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 정당 조회] 성공' );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>활동시작</td>";
					_tr +=  	"<td>활동종료</td>";
					_tr +=  	"<td>정당</td>";
					_tr +=  	"<td>코멘트</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.party )
					{
						var _item = data.party[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+_item[ 'start' ]+"</td>";
						_tr += 		"<td>"+_item[ 'end' ]+"</td>";
						_tr += 		"<td>"+toStringByParty( _item[ 'p_code' ] )+"</td>";
						_tr += 		"<td>"+_item[ 'memo' ]+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
				}else{
					setResultFailForJSON( '[모델 정당 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	
	//#################################################################
	//
	// 직책 정보
	//
	//#################################################################
	// 조회
	function selectModelDuty( $model_code )
	{
		var $container = $( '#modelDuty>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelDuty',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 직책 조회] 성공' );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>임무시작</td>";
					_tr +=  	"<td>임무종료</td>";
					_tr +=  	"<td>소속 당</td>";
					_tr +=  	"<td>직급</td>";
					_tr +=  	"<td>직책</td>";
					_tr +=  	"<td>완수여부</td>";
					_tr +=  	"<td>메모</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.duty )
					{
						var _item = data.duty[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+_item[ 'start' ]+"</td>";
						_tr += 		"<td>"+_item[ 'end' ]+"</td>";
						_tr += 		"<td>"+toStringByParty( _item[ 'p_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByRank( _item[ 'r_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByDuty( _item[ 'd_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByCompleted( _item[ 'com_code' ] )+"</td>";
						_tr += 		"<td>"+_item[ 'memo' ]+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
				}else{
					setResultFailForJSON( '[모델 직책 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	
	//#################################################################
	//
	// 약력 정보
	//
	//#################################################################
	// 조회
	function selectModelHistory( $model_code )
	{
		var $container = $( '#modelHistory>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelHistory',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 약력 조회] 성공' );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>구분</td>";
					_tr +=  	"<td>시작일</td>";
					_tr +=  	"<td>종료일</td>";
					_tr +=  	"<td>타이틀</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.history )
					{
						var _item = data.history[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+toStringByHistory( _item[ 'h_code' ] )+"</td>";
						_tr += 		"<td>"+_item[ 'start' ]+"</td>";
						_tr += 		"<td>"+_item[ 'end' ]+"</td>";
						_tr += 		"<td>"+_item[ 'memo' ]+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
				}else{
					setResultFailForJSON( '[모델 약력 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	//#################################################################
	//
	// 당선 정보
	//
	//#################################################################
	// 조회
	function selectModelElection( $model_code )
	{
		var $container = $( '#modelElection>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelElection',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 당선 조회] 성공' );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>당선일</td>";
					_tr +=  	"<td>지역구</td>";
					_tr +=  	"<td>출마당</td>";
					_tr +=  	"<td>비례대표여부</td>";
					_tr +=  	"<td>완수여부</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.elec )
					{
						var _item = data.elec[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+_item[ 'date' ]+"</td>";
						_tr += 		"<td>"+toStringByRegion( _item[ 'g_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByParty( _item[ 'p_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByBoolean( _item[ 'is_prop' ] )+"</td>";
						_tr += 		"<td>"+toStringByCompleted( _item[ 'com_code' ] )+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
				}else{
					setResultFailForJSON( '[모델 당선 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	//#################################################################
	//
	// 법안 연관 정보
	//
	//#################################################################
	// 조회
	function selectModelBussiness( $model_code )
	{
		var $container = $( '#modelBusiness>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelBusiness',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[연관 사업 조회] 성공' );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>사업명</td>";
					_tr +=  	"<td>활동상태</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.business )
					{
						var _item = data.business[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+_item[ 'b_name' ]+'('+_item[ 'b_code' ]+')'+"</td>";
						_tr += 		"<td>"+toStringByAction( _item[ 'a_code' ] )+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
				}else{
					setResultFailForJSON( '[연관 사업 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	//#################################################################
	//
	// SNS 정보
	//
	//#################################################################
	function selectModelSns( $modelCode )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelSns',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $modelCode
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[SNS 링크 조회] 성공' );
					
					var $listContainer = $( '#modelSns>.list' );
					$listContainer.empty();
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr += 		"<td>구분</td>";
					_tr +=  	"<td>LINK</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;
					for( var index in data.sns )
					{
						var _item = data.sns[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+toStringBySns( _item[ 's_code' ] )+"</td>";
						_tr += 		"<td>"+_item[ 'link' ]+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$listContainer.append( _tr );
				}else{
					setResultFailForJSON( '[SNS 링크 조회] 실패', data );
				}
			}
			,
			'json' 
		);
	}
	//#################################################################
	//
	// 태그 정보
	//
	//#################################################################
	function selectModelTags( $modelCode )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelTags',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $modelCode
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[정치인 태그 조회] 성공' );
					
					var $listContainer = $( '#modelTags>.list' );
					// 비우기
					$listContainer.empty();
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>TAG</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;
					for( var index in data.tag )
					{
						var _item = data.tag[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'tag' ]+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$listContainer.append( _tr );
				}else{
					setResultFailForJSON( '[사업 태그 조회] 실패', data );
				}
			}
			,
			'json' 
		);
	}
	
	//#################################################################
	//
	// 능력치 입력
	//
	//#################################################################
	// 조회
	function setStatField( $model_code )
	{
		$( 'table.modelStatList > tbody' ).empty();
		$( 'table.modelTendencyList > tbody' ).empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectMemberModelStat',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[능력치 조회] 성공' );
					
					initStatField( data );
					initTendencyField( data );
				}else{
					setResultFailForJSON( '[능력치 조회] 실패', data );
				}
			}
			,
			'json'
			);		
	}
	
	function initStatField( data )
	{
		var _tableBody = $( 'table.modelStatList > tbody' ).empty();
		var _datas = _g_statInfos[ 0 ];
		for( var idx in _datas )
		{
			var _tr = '';
			_tr += '<tr>';
			_tr += '	<td>'+_datas[ idx ].name+'</td>';
			_tr += '	<td>'+getStatAVG( _datas[ idx ].code )+'</td>';
			_tr += '	<td><input name="'+_datas[ idx ].code+'" type="text"/></td>';
			_tr += '</tr>';
			
			_tableBody.append( _tr );
		}
		
		for( idx in data.stat )
		{
			_tableBody.find( 'input[name="'+data.stat[ idx ][ 's_code' ]+'"]' ).val( data.stat[ idx ][ 'point' ] );
		}
	}
	
	function initTendencyField( data )
	{
		// 계산 함수
		function avgFunction( avg, count )
		{
			// 긍정수 = ( count*( 1+avg )/2 );
			// 부정수 = coount - 긍정수
			
			var _x = ( count*( 1+avg )/2 );
			var _y = count - _x;
			
			return avg+"(긍정 "+_x+"/부정 "+_y+")";
		}
		
		var _tableBody = $( 'table.modelTendencyList > tbody' ).empty();
		var _datas = _g_statInfos[ 1 ];
		for( var idx in _datas )
		{
			var _tr = '';
			_tr += '<tr>';
			_tr += '	<td>'+_datas[ idx ].name+'</td>';
			_tr += '	<td>'+getStatAVG( _datas[ idx ].code, avgFunction )+'</td>';
			_tr += '	<td><input name="'+_datas[ idx ].code+'" type="text"/></td>';
			_tr += '</tr>';
			
			_tableBody.append( _tr );
		}
		
		for( idx in data.stat )
		{
			_tableBody.find( 'input[name="'+data.stat[ idx ][ 's_code' ]+'"]' ).val( data.stat[ idx ][ 'point' ] );
		}
	}
	
	// 입력
	$( '#updateModelStatForm' ).submit( updateModelStat );
	$( '#updateModelTendencyForm' ).submit( updateModelStat );
	
	function updateModelStat( e )
	{
		e.preventDefault();
		
		var $model_code = $( this ).find( 'input[name="modelCode"]' ).val();
		var _codes = [];
		var _values = [];
		$( this ).find( 'tbody>tr>td>input[type="text"]' ).each(function(index, element) {
            var _v = $(this).val();
			if( isNaN( _v ) == false )
			{
				_codes.push( $(this).attr( 'name' ) );
				_values.push( _v );
			}
        });
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'updateMemberModelStat',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $model_code,
				codes: _codes,
				values: _values
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[능력치 업데이트] 성공' );
				}else{
					setResultFailForJSON( '[능력치 업데이트] 실패', data );
				}
			}
			,
			'json' );
	}
	
	//#################################################################
	//
	// 즐겨 찾기
	//
	//#################################################################
	// 조회
	function selectMemberModelFavorite( $model_code )
	{
		// 값을 담아둠
		$( '#btn_memberFavorite' ).attr( 'modelCode', $model_code );
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectMemberModelFavorite',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $model_code
			}
			,
			favoriteButtonRefresh
			,
			'json' );
	}
	
	// 업데이트
	$( '#btn_memberFavorite' ).click( function(e)
	{
		if( $( this ).attr( 'modelCode' ) == undefined ) return;
		
		// 'Y', 'N'
		var $isFavorite = $( this ).attr( 'isFavorite' ) == 'Y';
		var $model_code = $( this ).attr( 'modelCode' );
		
		if( $isFavorite )
		{
			// 해제
			$.post(
				getGatePath()
				,
				{
					__key__: 'deleteMemberModelFavorite',
					__returnType__: 'json',
					login_member_id: login_member_id(),
					login_member_session: login_member_session(),
					modelCode: $model_code
				}
				,
				favoriteButtonRefresh
				,
				'json'
			);
		}else{
			// 등록
			$.post(
				getGatePath()
				,
				{
					__key__: 'insertMemberModelFavorite',
					__returnType__: 'json',
					login_member_id: login_member_id(),
					login_member_session: login_member_session(),
					modelCode: $model_code
				}
				,
				favoriteButtonRefresh
				,
				'json'
			);
		}
			
		
		
	});
	
	function favoriteButtonRefresh( data )
	{
		if( data.result == 'SUCCESS' )
		{
			setResult( '[즐겨찾기] 성공' );
			if( data[ 'isFavorite' ] == 'Y' )
			{
				// 즐겨찾기에 등록되어 있는 모델이면, 해제 버튼으로 설정한다.
				$( '#btn_memberFavorite' ).attr( 'isFavorite', 'Y' );
				$( '#btn_memberFavorite' ).val( 'Like Down' );
			}else{
				// 즐겨찾기에 등록된 모델이 아니면, 등록 버튼으로 설정한다.
				$( '#btn_memberFavorite' ).attr( 'isFavorite', 'N' );
				$( '#btn_memberFavorite' ).val( 'Like Up' );
			}
		}else{
			setResultFailForJSON( '[즐겨찾기] 실패', data );
			$( '#btn_memberFavorite' ).removeAttr( 'modelCode' );
			$( '#btn_memberFavorite' ).removeAttr( 'isFavorite' );
			$( '#btn_memberFavorite' ).val( 'Impossible' );
		}
	}
	
	//#################################################################
	//
	// 댓글 달기
	//
	//#################################################################
	// 목록 조회
	var _commentPage 	= new PageInfo( document.getElementById( 'modelComments' ) );
	_commentPage.numPerPage = 5;
	$( '#btn_modelCommentRefresh' ).click(function(e) {
        selectAllModelComments( _commentPage.current, _commentPage.numPerPage, modelCommentsRefreshSuccess, modelCommentsRefreshFail );
    });
	
	function selectAllModelComments( page, numPerPage, completeHandler, failHandler )
	{
		$.post( getGatePath(),
		{
			__key__: 'selectModelComments',
			__returnType__: 'json',			
			login_member_id: login_member_id(),
			login_member_session: login_member_session(),
			modelCode: $( '#insertModelCommentForm' ).find( '.modelCode' ).val(),
			page: page,
			numPerPage: numPerPage
		},
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				// 완료 콜백
				if( completeHandler )
				{
					completeHandler.call( null, data );
				}
			}else{
				// 실패 콜백
				if( failHandler )
				{
					failHandler.call( null, data );
				}
			}
		},
		'json');
	}
	// 조회 성공
	function modelCommentsRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[모델 댓글 조회] 성공' );
		
		var $listContainer = $( "#modelComments>.list" );
		// 비우기
		$listContainer.find( '.btnDelete' ).unbind( "click" );
		$listContainer.empty();
		
		// 타이틀 추가
		var _tr;
		_tr = "<thead>";
		_tr += "<tr>";
		_tr += 		"<td>NO</td>";
		_tr +=  	"<td>댓글</td>";
		_tr +=  	"<td>작성자</td>";
		_tr +=  	"<td>등록일</td>";
		_tr +=  	"<td>DELETE</td>";
		_tr += "</tr>";
		_tr += "</thead>";
		_tr += "<tbody>";
		// 리스트 추가
		var _no = (_commentPage.current-1)*_commentPage.numPerPage+1;
		for( var index in data.comment )
		{
			var _item = data.comment[ index ];
			_tr += "<tr>";
			_tr += 		"<td>"+(_no++)+"</td>";
			_tr += 		"<td>"+_item[ 'comment' ]+"</td>";
			_tr += 		"<td>"+_item[ 'nickname' ]+"</td>";
			_tr += 		"<td>"+_item[ 'register' ]+"</td>";
			_tr += 		"<td>"+(_item[ 'owner_id' ]==login_member_id()?"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>":'')+"</td>";			
			_tr += "</tr>";
		}
		_tr += "</tbody>";
		$listContainer.append( _tr );
		
		// 수정 버튼 이벤트 등록
		$listContainer.find( '.btnDelete' ).bind( "click", null, function(e) {
			var $comment_seq = $(this).attr( 'data' );
			deleteModelComment( $comment_seq );
		});
		
		// 페이징
		_commentPage.setTotalCount( data.count );
		_commentPage.updateLabelField();
	}
	
	// 조회 실패
	function modelCommentsRefreshFail( data )
	{
		setResultFail( '[모델 댓글 조회] 실패', data );
	};
	
	// 입력
	$( '#insertModelCommentForm' ).submit(function(e) {
        e.preventDefault();
		
		
		var _formData = new FormData( document.getElementById( 'insertModelCommentForm' ) );
		_formData.append( '__key__', 'insertMemberModelComment' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[코멘트 추가] 성공' );
					// 리스트 갱신
					selectAllModelComments( _commentPage.current, _commentPage.numPerPage, modelCommentsRefreshSuccess, modelCommentsRefreshFail );
				}else{
					setResultFailForJSON( '[코멘트 추가] 실패', data );
				}
			}
		});
    });
	
	// 댓글 삭제
	function deleteModelComment( $comment_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteMemberModelComment',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $comment_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[코멘트 삭제] 성공' );
					// 리스트 갱신
					selectAllModelComments( _commentPage.current, _commentPage.numPerPage, modelCommentsRefreshSuccess, modelCommentsRefreshFail );
				}else{
					setResultFailForJSON( '[코멘트 삭제] 실패', data );
				}
			}
			,
			'json' );
	}
	
	//#################################################################
	//
	// 즐겨찾기 모델 조회부
	//
	//#################################################################
	// 목록 조회
	var _favoriteModelListPage 	= new PageInfo( document.getElementById( 'selectFavoriteModels' ) );
	$( "#favoriteModelRefresh" ).click(function(e) {
		selectFavoriteModels( _favoriteModelListPage.current, _favoriteModelListPage.numPerPage, favoriteModelRefreshSuccess, favoriteModelRefreshFail );
	});
	function selectFavoriteModels( page, numPerPage, completeHandler, failHandler )
	{
		$.post( getGatePath(),
		{
			__key__: 'selectFavoriteModels',
			__returnType__: 'json',
			login_member_id: login_member_id(),
			login_member_session: login_member_session(),
			page: page,
			numPerPage: numPerPage
		},
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				// 완료 콜백
				if( completeHandler )
				{
					completeHandler.call( null, data );
				}
			}else{
				// 실패 콜백
				if( failHandler )
				{
					failHandler.call( null, data );
				}
			}
		},
		'json' );
	}
	// 조회 성공
	function favoriteModelRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[모델 조회] 성공' );
		
		setModelListTable( data, $( "#selectFavoriteModels>.list" ), _favoriteModelListPage );
	}
	
	// 조회 실패
	function favoriteModelRefreshFail( data )
	{
		setResultFailForJSON( '[모델 조회] 실패', data );
	};
	
	//#################################################################
	//
	// 댓글남긴 모델 조회부
	//
	//#################################################################
	// 목록 조회
	var _commentModelListPage 	= new PageInfo( document.getElementById( 'selectCommentModels' ) );
	$( "#commentModelRefresh" ).click(function(e) {
		selectCommentModels( _commentModelListPage.current, _commentModelListPage.numPerPage, commentModelRefreshSuccess, commentModelRefreshFail );
	});
	function selectCommentModels( page, numPerPage, completeHandler, failHandler )
	{
		$.post( getGatePath(),
		{
			__key__: 'selectCommentModels',
			__returnType__: 'json',
			login_member_id: login_member_id(),
			login_member_session: login_member_session(),
			page: page,
			numPerPage: numPerPage
		},
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				// 완료 콜백
				if( completeHandler )
				{
					completeHandler.call( null, data );
				}
			}else{
				// 실패 콜백
				if( failHandler )
				{
					failHandler.call( null, data );
				}
			}
		},
		'json' );
	}
	// 조회 성공
	function commentModelRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[모델 조회] 성공' );
		
		setModelListTable( data, $( "#selectCommentModels>.list" ), _commentModelListPage );
	}
	
	// 조회 실패
	function commentModelRefreshFail( data )
	{
		setResultFailForJSON( '[모델 조회] 실패', data );
	};
	
	function setModelListTable( data, $listContainer, pageInfo )
	{
		// 비우기
		$listContainer.find( '.btnDetail' ).unbind( "click" );
		$listContainer.empty();
		
		// 타이틀 추가
		var _tr;
		_tr = "<thead>";
		_tr += "<tr>";
		_tr += 		"<td>NO</td>";
		_tr +=  	"<td>CODE</td>";
		_tr +=  	"<td>이름</td>";
		_tr +=  	"<td>대표이미지</td>";
		_tr +=  	"<td>출생일</td>";
		_tr +=  	"<td>출생지</td>";
		_tr +=  	"<td>최종학력</td>";
		_tr +=  	"<td>성별</td>";
		_tr +=  	"<td>병역</td>";
		_tr +=  	"<td>키</td>";
		_tr +=  	"<td>자료출처</td>";
		_tr +=  	"<td>DETAIL</td>";
		_tr += "</tr>";
		_tr += "</thead>";
		_tr += "<tbody>";
		// 리스트 추가
		var _no = (pageInfo.current-1)*pageInfo.numPerPage+1;
		for( var index in data.model )
		{
			var _item = data.model[ index ];
			_tr += "<tr>";
			_tr += 		"<td>"+(_no++)+"</td>";
			_tr += 		"<td>"+_item[ 'code' ]+"</td>";
			_tr += 		"<td>"+_item[ 'name' ]+"</td>";
			_tr += 		"<td>"+_item[ 'picture' ]+"</td>";
			_tr += 		"<td>"+_item[ 'birth_date' ]+"</td>";
			_tr += 		"<td>"+toStringByRegion( _item[ 'birth_region' ] )+"</td>";
			_tr += 		"<td>"+toStringByEducation( _item[ 'last_edu' ] )+"</td>";
			_tr += 		"<td>"+toStringBySex( _item[ 'sex' ] )+"</td>";
			_tr += 		"<td>"+toStringByMilitary( _item[ 'military' ] )+"</td>";
			_tr += 		"<td>"+_item[ 'height' ]+"</td>";
			_tr += 		"<td>"+_item[ 'ref' ]+"/"+_item[ 'ref_license' ]+"</td>";
			_tr += 		"<td>"+"<input type='button' class='btnDetail' value='DETAIL' data='"+_item[ 'code' ]+"'/>"+"</td>";
			_tr += "</tr>";
		}
		_tr += "</tbody>";
		$listContainer.append( _tr );
		
		// 수정 버튼 이벤트 등록
		$listContainer.find( '.btnDetail' ).bind( "click", null, function(e) {
			// alert( 'EDIT '+$(this).attr( 'data' ) );
			var $model_code = $(this).attr( 'data' );
			showDetailModelPopup( $model_code );
		});
		
		// 페이징
		pageInfo.setTotalCount( data.count );
		pageInfo.updateLabelField();
	}
}